
package com.v1.video.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.v1.video.R;
import com.v1.video.domain.OptionInfo;

/**
 * 消息提醒类；
 * 
 * @author Administrator
 */
public class OptionUploadSetActivity extends BaseActivity {

    private final String TAG = "OptionUploadSetActivity";

    private OptionUploadSetActivity instance;
    public static final int PASS_NET_ANY = 1011;
    public static final int PASS_NET_WIFI = 1012;

    // setText(Html.fromHtml("<u>"+"hahaha"+"</u>"));

    /** 标题 */
    TextView text_title;

    /** 返回按钮 */
    private ImageView view_btn_return;

    /** 任何网络上传按钮 */
    private ImageView btnAnyInternet;
    private RelativeLayout layoutAnyInternet;

    /** 是否任何网络上传 */
    public boolean isAnyInternet = false;

    /** 仅wifi上传按钮 */
    private ImageView btnOnlyWifi;
    private RelativeLayout layoutOnlyWifi;

    /** 是否仅Wifi上传 */
    public boolean isOnlyWifi = true;

    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_option_upload_set);
        instance = this;
    }

    @Override
    protected void initView() {
        // TODO Auto-generated method stub
       
        view_btn_return = (ImageView) findViewById(R.id.iv_result);
        text_title = (TextView) findViewById(R.id.tv_title);

        btnAnyInternet = (ImageView) findViewById(R.id.option_upload_any_click);
        btnOnlyWifi = (ImageView) findViewById(R.id.option_upload_only_click);
        layoutAnyInternet = (RelativeLayout) findViewById(R.id.option_upload_any_back);
        layoutOnlyWifi = (RelativeLayout) findViewById(R.id.option_upload_wifi_back);
        
    }

    @Override
    protected void initData() {
        // TODO Auto-generated method stub
        text_title.setText(R.string.option_item_upload);
        if(OptionInfo.getInstance(OptionUploadSetActivity.this).isUploadAny()){
            btnAnyInternet.setImageResource(R.drawable.btn_select_on_option);
            isAnyInternet = true;
            btnOnlyWifi.setImageResource(R.drawable.btn_select_down_option);
            isOnlyWifi = false;
        }else{
            btnAnyInternet.setImageResource(R.drawable.btn_select_down_option);
            isAnyInternet = false;
            btnOnlyWifi.setImageResource(R.drawable.btn_select_on_option);
            isOnlyWifi = true;
        }
    }

    @Override
    protected void setListener() {
        // TODO Auto-generated method stub
        findViewById(R.id.lay_result).setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                finish();
            }
        });
        btnInfoReceiveOnclick();

    }

    private void btnInfoReceiveOnclick() {
        layoutAnyInternet.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                if (isAnyInternet) {                    
                    btnAnyInternet.setImageResource(R.drawable.btn_select_down_option);
                    isAnyInternet = false;
                    btnOnlyWifi.setImageResource(R.drawable.btn_select_on_option);
                    isOnlyWifi = true;
                    OptionInfo.getInstance(OptionUploadSetActivity.this).setUploadAny(false);
                    OptionInfo.getInstance(OptionUploadSetActivity.this).saveData(OptionUploadSetActivity.this);
                } else {
                    btnAnyInternet.setImageResource(R.drawable.btn_select_on_option);
                    isAnyInternet = true;
                    btnOnlyWifi.setImageResource(R.drawable.btn_select_down_option);
                    isOnlyWifi = false;
                    OptionInfo.getInstance(OptionUploadSetActivity.this).setUploadAny(true);
                    OptionInfo.getInstance(OptionUploadSetActivity.this).saveData(OptionUploadSetActivity.this);
                }
            }
        });
        layoutOnlyWifi.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                if (isOnlyWifi) {
                    btnOnlyWifi.setImageResource(R.drawable.btn_select_down_option);
                    isOnlyWifi = false;
                    btnAnyInternet.setImageResource(R.drawable.btn_select_on_option);
                    isAnyInternet = true;
                    OptionInfo.getInstance(OptionUploadSetActivity.this).setUploadAny(true);
                    OptionInfo.getInstance(OptionUploadSetActivity.this).saveData(OptionUploadSetActivity.this);
                } else {
                    btnOnlyWifi.setImageResource(R.drawable.btn_select_on_option);
                    isOnlyWifi = true;
                    btnAnyInternet.setImageResource(R.drawable.btn_select_down_option);
                    isAnyInternet = false;
                    OptionInfo.getInstance(OptionUploadSetActivity.this).setUploadAny(false);
                    OptionInfo.getInstance(OptionUploadSetActivity.this).saveData(OptionUploadSetActivity.this);
                }
            }
        });
        
    }
    
    @Override
    public void onBackPressed() {
        // TODO Auto-generated method stub
        
        setResult();
    }

   private void setResult(){
       Intent intent = new Intent();
       intent.setClass(OptionUploadSetActivity.this, PersonalOptionActivity.class);
       if(isOnlyWifi){                
           setResult(PASS_NET_WIFI,intent);
       }else{
           setResult(PASS_NET_ANY,intent);
       }
       
       finish();
   }
}
